package nbcp.http.model

import nbcp.base.extend.HasValue
import java.time.LocalDateTime

/**
 * 资产实体对象
 */
class NexusAssetEntity {
    var downloadUrl: String = ""
    var path: String = ""
    var maven2: NexusMaven2Entity? = null
    var npm: NpmEntity? = null
    var repository: String = ""
    var lastModified: LocalDateTime = LocalDateTime.MAX

    val version: String
        get() {
            if (maven2 != null && maven2!!.version.HasValue) {
                if (repository.contains("snapshot", true)) {
                    var l = maven2!!.groupId.split(".").size +
                            maven2!!.artifactId.split(".").size

                    return path.split("/").elementAt(l);
                } else {
                    return maven2!!.version;
                }
            }

            if (npm != null && npm!!.version.HasValue) {
                return npm!!.version
            }

            return "";
        }
}
